var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inid:'',
    news_info: [],
  },

/**
   * 获取搜索商品详情
   */
  get_news_details:function(){
  	  var that = this;
  	  wx.showLoading({
  	    title: '加载中',
  	  })
  	  wx.request({
  	    url: app.domain_path + app.api_path + '/get_news_info',
  	    method: 'post',
  	    data: { 
          inid: that.data.inid,
  	    },
  	    header: {
  	      'content-type': 'application/x-www-form-urlencoded'
  	    },
  	    success: function(res) {
          console.log(res);
  	      if (!res.data) {
  	        wx.showToast({
  	          title: '加载错误',
  	          icon: 'loading',
  	          duration: 10000
  	        })
  	      }
  	      if (res.data.RESULT == 'OK') {
  	        wx.hideLoading();
  	  	  	that.setData({
  	  	  	  news_info: res.data.data.news_info,
  	  	  	}),
            //商品描述富文本编辑器
            WxParse.wxParse('article', 'html', that.data.news_info.news_contents, that, 5);
  	      } else {
            wx.hideLoading();
            wx.showModal({
              title: '温馨提示',
              content: res.data.MESSAGE,
              showCancel: false,
              success: function(res) {
              if (res.confirm) {
                wx.reLaunch({
                url: '/pages/news-list/news-list',
                })
              }
              }
            });
  	      }
  	    }
  	  })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id);
      var that = this;
      that.setData({
        inid: options.id,
      });
      that.get_news_details();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})